package com.wangyadong.hobby.schedule.jobtask.ath.lesson1;

import com.wangyadong.hobby.schedule.jobtask.ath.common.StdIn;
import com.wangyadong.hobby.schedule.jobtask.ath.common.StdOut;

/**
 * <p>
 *
 * @author <714037465@qq.com>
 * @since 2019/4/1614:39
 **/
public class StringTestExample {

    public static void main(String[] args) {
//        System.out.println("是否是回文--》" + isPalindrome("12345321"));
//        extName(args);
//        stantExtName(args);
//        emptyBlankString();
        System.out.println("是否字母顺序"+isSorted(args));

    }

    /**
     * 是否是回文参数
     *
     * @param s
     * @return
     */
    public static boolean isPalindrome(String s) {
        int length = s.length();
        for (int i = 0; i < length / 2; i++) {
            if (s.charAt(i) != s.charAt(length - 1 - i)) {
                return false;
            }
        }
        return true;
    }

    /***
     * 扩展名和名称
     * @param args
     */
    public static void extName(String[] args) {
        String arg = args[0];
        int dot = arg.indexOf(".");
        String base = arg.substring(0, dot);
        String extension = arg.substring(dot + 1, arg.length());
        System.out.println("name is" + base + "          " + extension);
    }

    public static void stantExtName(String[] args) {
        String query = args[0];
        while (!StdIn.isEmpty()) {
            String s = StdIn.readLine();
            if (s.contains(query)) {
                StdOut.println(s);
            }
        }
    }

    public static void emptyBlankString() {
        String input = StdIn.readAll();
        String[] split = input.split("\\s+");
        System.out.println(split);
    }

    public static boolean isSorted(String[] args) {
        for (int i = 1; i < args.length; i++) {
            if (args[i - 1].compareTo(args[i]) > 0) {
                return false;
            }
        }
        return true;
    }


}
